#include "video_generater.h"


VideoGenerater::VideoGenerater(int width, int height)
{
    image = cv::Mat(height,width, CV_8UC3, cv::Scalar(0x1a, 0xa3, 0xff));
	auto cnt_time = std::chrono::system_clock::now().time_since_epoch();
	start_time_ms = std::chrono::duration_cast<std::chrono::milliseconds>(cnt_time).count();

}

VideoGenerater::~VideoGenerater(){}




void VideoGenerater::genRGBFrame(cv::Mat& out_image)
{
    cv::Mat img_res = image.clone();
	auto cnt_time = std::chrono::system_clock::now().time_since_epoch();
	uint64_t cnt_time_ms = std::chrono::duration_cast<std::chrono::milliseconds>(cnt_time).count()-start_time_ms;


    std::string text_label = fmt::format("{}.{:03d}s",cnt_time_ms/1000,cnt_time_ms%1000);
    // std::string text_label = fmt::format("{}.{:03d}s",cnt_time_ms/1000,(int)cnt_time_ms%1000);


	int font_face = cv::FONT_HERSHEY_COMPLEX; 
	double font_scale = 4;
	int thickness = 4;
	int baseline;
	//获取文本框的长宽
	cv::Size text_size = cv::getTextSize(text_label, font_face, font_scale, thickness, &baseline);
 
	//将文本框居中绘制
	cv::Point origin; 
	origin.x = img_res.cols / 2 - text_size.width / 2;
	origin.y = img_res.rows / 2 + text_size.height / 2;
	cv::putText(img_res, text_label, origin, font_face, font_scale, cv::Scalar(0, 0, 0), thickness, 8, 0);
    // cv::imshow("image", img_res);
	// cv::waitKey(1);

    out_image = img_res;
    cnt_frame_idx ++;
}


